<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'mortgage.label', default: 'Mortgage')}"/>
    <title>房地产类押品</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>
                        <span>CINDTATA PLS</span>
                    </li>
                    <li>
                        <span>房地产</span>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>

<g:if test="${params?.message}">
    <div class="message alert alert-info" role="status">${params?.message}</div>
</g:if>

<g:if test="${flash.message}">
    <div class="message alert alert-info" role="status">${flash.message}</div>
</g:if>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="index" class="form-horizontal myForm" role="form" id="form" onsubmit="return text();">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="button" id="search"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn"><i class="fa fa-times"></i> 重置</button>
                        <button class="btn btn-info btn-xs" type="button" onclick="openModal(this);"><i class="fa fa-search"></i> 保存为批次</button>
                    </div>
                    查询
                </div>
                    <div class="panel-body seach-group" id="bug1">
                    %{--第一行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label for="city" class="col-sm-3 control-label">城市</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="city" id="city" from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}"
                                          valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                          value="${params?.city}"
                                          noSelection="${["-1": '请选择城市']}"/>
                                <input type="hidden" id="communityId" value="${params?.communityId}" name="communityId" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label for="district" class="col-sm-3 control-label">行政区</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="district" id="district"
                                          from="${districtList}"
                                          valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                          value="${params?.district}"
                                          noSelection="${["null": '请选择行政区']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">押品状态</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="estateStatus" id="estateStatus"
                                          from="${com.cindata.dictionary.EstateStatusDict.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.estateStatus}"
                                          noSelection="${["": '请选择押品状态']}"/>
                            </div>
                        </div>
                    </div>
                    %{--第二行--}%
                    <div class="row ">
                        <div id="reportStatus" style="display:none">
                            <input type="text" id="report" name="report">
                            <input type="text" id="numberTemp" name="numberTemp">
                            <input type="text" id="evaluateTypeTemp" name="evaluateTypeTemp">
                        </div>

                        <div class="form-group col-sm-4">
                            <label for="district" class="col-sm-3 control-label">押品名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="name" id="name" value="${params?.name}" placeholder="请输入押品名称">
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" >押品风险</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="risk" id="risk"
                                          from="${com.cindata.dimension.RiskDimension.list()}"
                                          valueMessagePrefix="status" optionKey="label" optionValue="label"
                                          value="${params?.risk}"
                                          noSelection="${["": '请选择押品风险']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label  class="col-sm-3 control-label">面积范围</label>
                            <div class="col-sm-9  input-group">
                                <input type="text" class=" form-control " placeholder="请输入下限" id="buildAreaStart" maxlength="6"
                                       value="${params?.buildAreaStart}" name="buildAreaStart" />
                                <span class="input-group-addon">至</span>
                                <input type="text" class="form-control " placeholder="请输入上限" id="buildAreaEnd" maxlength="6"
                                       value="${params?.buildAreaEnd}" name="buildAreaEnd" />
                            </div>

                        </div>
                        <div class="p-t-xss" style="position: absolute;z-index: 2;right: 40px;">
                            平米
                        </div>
                    </div>
                    %{--第三行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">房屋用途</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="buildingType" id="buildingType"
                                          from="${com.cindata.dictionary.BuildingTypeDict.listOrderById()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.buildingType}"
                                          noSelection="${["": '请选择房屋用途']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label for="district" class="col-sm-3 control-label">房屋详细地址</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="sourceAddress" id="sourceAddress" value="${params?.sourceAddress}" placeholder="请输入房屋详细地址">
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">变现能力</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="cashability" id="cashability"
                                          from="${com.cindata.dictionary.Cashability.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.cashability}"
                                          noSelection="${["": '请选择变现能力']}"/>
                            </div>
                        </div>
                    </div>
                    %{--第四行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label for="district" class="col-sm-3 control-label">押品编号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="externalId" id="externalId" value="${params?.externalId}" placeholder="请输入押品编号">
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">评估机构</label>
                            <div class="col-sm-9">
                                <g:select class="form-control m-b" name="latestEvaluateAccount" id="latestEvaluateAccount" from="${com.cindata.Account.findAllByType(com.cindata.dictionary.AccountTypeDict.EVALUATE())}" optionValue="name" optionKey="id" value="${params?.latestEvaluateAccount}" noSelection="${['': '请选择评估机构']}"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </g:form>
    </div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <button class="btn btn-warning2 btn-xs" type="submit" onclick="searchMap()"><i class="fa fa-map-marker"></i> 查看地图</button>
                    %{--<g:link action="create" class="btn btn-info btn-xs"><i class="fa fa-plus"></i>新建</g:link>--}%
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                &nbsp;&nbsp;
            </div>

            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="esateTable">
                        <thead>
                            <tr>
                                <!-- <th style="width: 60px;"><input type="checkbox" class="i-checks allCheckbox" id="allOptionId"></th> -->
                                <g:sortableColumn property="externalId" title="押品编号"   params="${params}"/>
                                <g:sortableColumn property="buildingType" title="房屋用途"    params="${params}"/>
                                <g:sortableColumn property="estateStatus" title="押品状态"   params="${params}"/>
                                <g:sortableColumn property="name" title="押品名称"    params="${params}"/>
                                <g:sortableColumn property="city" title="城市"    params="${params}"/>
                                <g:sortableColumn property="district" title="行政区"    params="${params}"/>
                                <g:sortableColumn property="fullName" title="抵押人名称"    params="${params}"/>
                                <g:sortableColumn property="sourceAddress" title="房屋详细地址"   params="${params}"/>
                                <g:sortableColumn property="sourceBuildArea" title="面积"   params="${params}"/>
                                <g:sortableColumn property="registerFullName" title="登记人"   params="${params}"/>
                                <g:sortableColumn property="registerAccount" title="登记机构"    params="${params}"/>
                                <g:sortableColumn property="registerDate" title="登记日期"    params="${params}"/>
                                <g:sortableColumn property="cashability" title="变现能力"   params="${params}"/>
                                <g:sortableColumn property="latestEvaluatePrice" title="最新评估价值"   params="${params}"/>
                                <g:sortableColumn property="latestEvaluateDate" title="最新评估日期"   params="${params}"/>
                                <g:sortableColumn property="cltv" title="押品风险"  params="${params}"/>
                                <g:sortableColumn property="latestEvaluateAccount" title="评估机构"  params="${params}"/>
                                <sec:ifAllGranted roles="ROLE_CUSTOMER_MANAGER">
                                    <th style="color: #34495e;" colspan="2">操作项</th>
                                </sec:ifAllGranted>
                                <sec:ifNotGranted roles="ROLE_CUSTOMER_MANAGER">
                                    <th style="color: #34495e;">操作项</th>
                                </sec:ifNotGranted>
                            </tr>
                        </thead>
                        <tbody>
                            <g:each in="${collateralList}">
                                <tr>
                                    <td ><g:link style="color: #3498DB" action="show" class="firstTd" id="${it?.id}">${it.externalId}</g:link></td>
                                    <td>${it?.estate?.buildingType?.name}</td>
                                    <td>${it?.estateStatus?.name}</td>
                                    <td>${it?.name}</td>
                                    <td>${it?.city?.name}</td>
                                    <td>${it?.district?.name}</td>
                                    <td>${it?.fullName}</td>
                                    <td>${it?.estate?.sourceAddress}</td>
                                    <td>${it?.estate?.buildArea}</td>
                                    <td>${it?.registerFullName}</td>
                                    <td>${it?.registerAccount}</td>
                                    <td>
                                        <g:if test="${it?.registerDate}">
                                            <g:formatDate date="${it?.registerDate}" format="yyyy-MM-dd HH:mm:ss"></g:formatDate>
                                        </g:if>
                                    </td>
                                    <td>${it?.cashability?.name}</td>
                                    <td class="prices">
                                        <g:if test="${it?.latestEvaluatePrice}">
                                            <g:formatNumber number="${it?.latestEvaluatePrice}" minFractionDigits="2" maxFractionDigits="2"/>
                                        </g:if>
                                    </td>
                                    <td class="date">
                                        <g:if test="${it?.latestEvaluateDate}">
                                            <g:formatDate date="${it?.latestEvaluateDate}" format="yyyy-MM-dd HH:mm:ss"></g:formatDate>
                                        </g:if>
                                    </td>
                                    <td>
                                        <g:if test="${it?.cltv>=0&&it?.cltv<=0.6}">低</g:if>
                                        <g:if test="${it?.cltv>0.6&&it?.cltv<=0.8}">中</g:if>
                                        <g:if test="${it?.cltv>0.8&&it?.cltv<=1}">高</g:if>
                                        <g:if test="${it?.cltv>1}">损失</g:if>
                                    </td>
                                    <td>
                                        ${it?.estate?.latestEvaluateAccount}
                                    </td>
                                    <td>
                                        <div style="margin-bottom: 2px;">
                                            <a href="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                                评估
                                            </a>
                                        </div>
                                    </td>
                                    %{--<sec:ifAllGranted roles="ROLE_CUSTOMER_MANAGER">
                                        <td>
                                            <div style="margin-bottom: 2px;">
                                                <a class="btn btn-xs btn-outline btn-info" href="#" data-toggle="modal" data-target="#outOfStorageModal" onclick="getInfo(${it.id})">
                                                    申请出入库
                                                </a>
                                            </div>
                                        </td>
                                    </sec:ifAllGranted>--}%
                                </tr>
                            </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="index" total="${collateralCount ?: 0}" params="${params}"/>
                </div>
            </div>
        </div>
    </div>
</div>

%{--出入库申请--}%
<div class="modal fade" id="outOfStorageModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="color-line"></div>

            <div class="modal-header">
                <h5 class="modal-title">出入库申请</h5>
            </div>

            <div class="modal-body">
                <div class="form-group">
                    <label class="col-md-3 control-label">出入库流程</label>
                    <div class="col-sm-6">
                        <input type="hidden" name="collateralId" id="collateralId" value="">
                        <g:select class="form-control" name="workFlowId" id="workFlowId"
                                  from="${com.cindata.Workflow.findAllByType(com.cindata.dictionary.WorkflowType.findByName('押品'))}"
                                  valueMessagePrefix="status" optionKey="id" optionValue="name"
                                  value="${params?.workFlowId}"
                                  noSelection="${['': '请选择出入库流程']}"/>
                    </div>
                </div>
            </div>

            <div class="hr-line-dashed"></div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clearInfo()">取消</button>
            </div>
        </div>
    </div>
</div>

%{--弹框--}%
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="color-line" style="background: #3498db"></div>
            <div class="modal-header text-center">
                <h4 class="modal-title">该批次记录${collateralCount}条，是否确认保存？</h4>
            </div>
            <div class="modal-body">
                <g:form class="form-horizontal packForm" controller="abnormalMortgageBatch" action="batchSave" method="post">
                    <div class="modal-body">
                      <div class="form-group">
                          <label class="col-md-3 control-label is-required">批次名称</label>
                          <div class="col-md-9">
                              <div>
                                  <input type="text" class="form-control" id="number" name="number" value="${new java.text.SimpleDateFormat('yyyyMMddHHmmss').format(new Date())}" readonly="true" />
                              </div>
                          </div>
                      </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">评估方式</label>
                            <div class="col-md-9">
                              <g:select class="form-control" name="evaluateType.id" id="evaluateType" value="${params?.evaluateType}" from="${com.cindata.dictionary.EvaluateDict.list()}" optionKey="id" optionValue="name" noSelection="['': '请选择评估方式']"></g:select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModal">关闭</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" id="download">保存</button>
                    </div>
                </g:form>
            </div>
        </div>
    </div>
</div>

<g:javascript>
        
    $(".batchEvaluateSubmit").click(function() {

        var batchNumber = $("#batchNumber").val()
        if (!batchNumber) {
            toastr.error('请选择批次名');
            return;
        }

        var evaluateType = $('input[name="evaluateType"]:checked').val()
        if (!evaluateType)
        {
            toastr.error('请选择评估类型');
            return;
        }

        var latestEvaluateAccountName = $("#latestEvaluateAccountName").val()
        if (evaluateType == '10' && !latestEvaluateAccountName)
        {
            toastr.error('请选择评估机构');
            return;
        }

        if (evaluateType != "10")
        {
            $("#latestEvaluateAccountName").val("")
        }

        $(".batchEvaluate").submit();
    })

    $("input[name='evaluateType']").bind("click",function()
    {
       if ($(this).val() == 10)
       {
            $('#evaluateAccount').removeClass("hidden");
       }
       else
       {
            $('#evaluateAccount').addClass("hidden");
       }
    });

    function getInfo(id){
        $("#collateralId").val(id);
    }
    function clearInfo(){
        $("#workFlowId").val("");
        $('#s2id_stage span:first').html('请选择出入库工作流');
    }
    //出入库申请
    $("#confirm").click(function () {
        var workFlowId = $("#workFlowId").val();
        var id =  $("#collateralId").val();
        if(!workFlowId){
             toastr.error('请选择出入库工作流！');
             return
        }
        var data = {
            workFlowId:workFlowId,
            id:id
        };
        $.ajax({
            type:"post",
            url: "/estate/outOfStorage",
            data:data,
            success: function (mes) {
                if(mes.status == "success") {
                    $("#outOfStorageModal").modal("hide");
                    $("#workFlowId").val("");
                    $('#s2id_stage span:first').html('请选择出入库工作流');
                    swal({
                        title: "申请成功",
                        type: "success"
                    });
                    var targetUri = mes.targetUri;
                    window.location.href = targetUri;
                }else {
                   swal("申请失败，请稍后重试", "", "error");
                }
            }
        })
    });

    var checkAll =$('.allCheckbox');  //全选的input
    var checkboxs =$('.everyCheckbox'); //所有单选的input

    checkAll.on('ifChecked ifUnchecked',function(event){
        if(event.type == 'ifChecked'){
            checkboxs.iCheck('check');
        }else{
            checkboxs.iCheck('uncheck');
        }
    });

    checkboxs.on('ifChanged',function(event){
        if(checkboxs.filter(':checked').length == checkboxs.length){
            checkAll.prop('checked',true);
        }else{
            checkAll.prop('checked',false);
        }
        checkAll.iCheck('update');
    });
    //单条评估
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        var thats = $(this);
        swal({
            title: "确定评估该押品吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
        function(){
            $.ajax({
                url:'/valuationHistory/estateEvaluate',
                data:{
                    id:id,
                    sourceClass: 'estate'
                },
                type:"post",
                success:function(data)
                {
                    if(data.status=="success"){
                        var price = data.price.toFixed(2)
                        var date = data.date
                        $(thats).parent().parent().siblings(".prices").text(price);
                        $(thats).parent().parent().siblings(".date").text(date);
                    }else{
                        swal("评估失败，请稍后重试", "", "error");
                    }
                }
            })
        });
    });
    function searchMap() {
        var city = $("#city").val();
        if(city=="-1"){
            toastr.error('请选择城市');
            return
        }
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
    $(function () {
        $('#datepicker').datepicker({
            language: 'zh-CN'
        });
        $("#datepicker").on("changeDate", function(event) {
            $("#my_hidden_input").val(
                    $("#datepicker").datepicker('getFormattedDate')
            )
        });

        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
        var flag;
        $("#city").bind("change", function(){
            if('${params.district}'== $("#district option:selected").val()&&flag!=true && '${params.district}' != '-1'){
                flag=true
                return
            }
            $("#district option").remove();
            $("#s2id_district span:first").html("请选择行政区");
            var city = $("#city").val()
            $("#district").append("<option value='-1' >请选择行政区</option>")
            if(city=='-1'){
                return
            }
            $.ajax({
                url: "/estate/districtList",
                type: "POST",
                data: {'city': city} ,
                success: function(result){
                    for(var i=0; i < result.districtList.length; i++){
                        $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                    }
                }
            });
        });
        $("#city").change();
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#communityId").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_district span:first").html("请选择行政区");
        $("#district").val("");
        $('#s2id_estateStatus span:first').html('请选择押品状态');
        $('#estateStatus').val('');
        $("#sourceAddress").val("");
        $("#name").val("");
        $('#s2id_risk span:first').html('请选择押品风险');
        $('#risk').val("");
        $('#s2id_mortgageStatus span:first').html('请选择贷款状态');
        $('#mortgageStatus').val("");
        $('#s2id_buildingType span:first').html('请选择房屋用途');
        $('#buildingType').val("");
        $("#buildAreaStart").val("");
        $("#buildAreaEnd").val("");
        $('#s2id_cashability span:first').html('请选择变现能力');
        $("#cashability").val("")
        $('#s2id_batch span:first').html('请选择批次名');
        $("#batch").val("")
        $('#s2id_latestEvaluateAccount span:first').html('请选择评估机构');
        $("#latestEvaluateAccount").val("");
        $("#report").val("");
        $("#externalId").val("");
    });

    $("#search").click(function () {
        $("#report").val("");
        $("#search").attr("type", "submit");
    });

    // 限制
    $(function(){
        function text(){
            if(buildAreaStart.value<0||buildAreaStart.value>214748||buildAreaEnd.value<0||buildAreaEnd.value>214748){
                toastr.error('值应0-214748之间');
                buildAreaStart.value='';
                buildAreaEnd.value='';
            }
        }
    })

    //弹出模态框
    function openModal(obj) {
        $('#myModal').modal('show');
    }
</g:javascript>

<script type="text/javascript">
    $("#download").click(function(event) {
        var evaluateType = $("#evaluateType").val();
        var number = $("#number").val();
        var total = ${collateralCount};
        // if (total > 5000)
        // {
        //     toastr.error("对不起，批次条数不能超过2000条！")
        //     return
        // }
        $("#report").val("yes");
        $("#evaluateTypeTemp").val(evaluateType);
        $("#numberTemp").val(number);
        $(".myForm").submit();
    });
</script>
</body>
</html>